﻿using System.Xml.Serialization;

namespace UTable.Core.Configuration
{
    /// <summary>
    /// UTable Configuration, including configurations of Window, Input, etc.
    /// </summary>
    [XmlRoot("UTable", Namespace = "", IsNullable = false)]
    public class Configuration
    {
        #region Properties

        public bool Debug { get; set; }

        /// <summary>
        /// The configuration of base Window, including size and position
        /// </summary>
        public WindowConfiguration Window { get; set; }

        /// <summary>
        /// The configuration of multi-modal input
        /// </summary>
        public InputConfiguration Input { get; set; }

        /// <summary>
        /// The class type of Tabletop.
        /// </summary>
        public TabletopConfiguration Tabletop { get; set; }

        #endregion

        #region Static Methods

        public static Configuration GetDefaultConfiguration()
        {
            Configuration configuration = new Configuration();
            configuration.Debug = true;
            
            configuration.Window = new WindowConfiguration();
            configuration.Window.Maximized = true;

            configuration.Input = new InputConfiguration();
            ClassConfiguration miceclass = new ClassConfiguration();
            miceclass.TypeString = "UTable.Core.Input.MultiMouseProvider";
            miceclass.Assembly = "UTable.Core";
            miceclass.SetType();
            ProviderConfiguration mice = new ProviderConfiguration();
            mice.Class = miceclass;
            mice.CreateInstance();
            configuration.Input.Providers.Add(mice);

            configuration.Tabletop = new TabletopConfiguration();
            configuration.Tabletop.Class = new ClassConfiguration();
            configuration.Tabletop.Class.TypeString = "UTable.Core.Objects.Controls.Tabletop.BlankTabletop";
            configuration.Tabletop.Class.Assembly = "UTable.Core";
            configuration.Tabletop.Class.SetType();

            return configuration;
        }

        public static Configuration GetConfigurationFromXml(string filepath)
        {
            Configuration configuration =  ConfigurationXMLSerializer.Load(filepath);
            foreach (ProviderConfiguration providerConfiguration in configuration.Input.Providers)
            {
                providerConfiguration.Class.SetType();
                providerConfiguration.CreateInstance();
            }
            return configuration;
        }

        #endregion
    }
}
